trace("included main.as");

import mx.utils.Delegate;

//include Timber data classes for XML
import timber.data.*;


// ===========================================================
// - LOAD CONFIG XML DATA
// ===========================================================
function load (url:String, callback:Function){
	trace("load");
	this.url = url;
	this.callback = callback;
	//parse config xml
	videosData = new XMLData(url, Delegate.create(this, loadSuccess));
}

function loadSuccess (val:Boolean){
	if (val) {
		var msg:String = "xml data success!";
		trace(msg);
		loadBlog();
	} else {
		//display big error message
		var msg:String = "Error loading config file.";
		trace(msg);
		//displayError(msg);
	}
}

function loadBlog() {
	trace("loadBlog");
	var newsLength = videosData.playlist.video.length;
	trace("_global.videosData:")
	trace(_global.videosData);
	
	var newsText = "";
	for (var i=0;i<newsLength;i++) {
		var currItem = videosData.playlist.video[i];
		newsText += "<b>"+currItem.headline+"</b>";
		newsText += newline;
	}
	
	trace (newsText)
	blog_mc.blog_txt.htmlText = newsText;
}

//extra
function formatString(str:String):String{
	trace("CTLR formatString");
	str = str.split("<p>").join("");
	str = str.split("</p>").join("\r");
	return str;
};


function start() {
	var result_lv:LoadVars = new LoadVars();
    result_lv.onLoad = function(success:Boolean) {
    if (success) {
        //result_ta.text = result_lv.welcomeMessage;
		//trace("result "+result_lv.xmlString);
		//load(result_lv.xmlString, loadSuccess);
		trace("xmlString (from php page):")
		trace(result_lv.xmlString);
		//_global.videosData = XMLData.createWithString(result_lv.xmlString,Delegate.create(this, loadSuccess));
		_global.videosData = new XMLData({source:result_lv.xmlString}, Delegate.create(this, loadSuccess))
	} else {
        trace("error getting data from send load")
    }
	}
	var send_lv:LoadVars = new LoadVars();
    send_lv.name = "testing.";
    send_lv.sendAndLoad("testXML.php", result_lv, "POST");
/*
	//var xml = "testXML.php";
	var xml = "_xml/playlist.xml";
	load(xml, loadSuccess);*/
}

start();
